module V{
    /** 子弹 */
    export class BuyuBullet{
        /** 动画对象 */
        public mv:egret.MovieClip;
        /** 速度 */
        private speed:number;
        /** 弧度 */
        private rad:number;
        /** 鱼网 */
        private img:egret.Bitmap;
        /** 椅子号 */
        public chairId:number;
        /** 子弹id */
        public bulletId:number;
        /** 子弹类型 */
        public bulletKind:number;
        /** 子弹值 */
        public bulletMul:number;

        /** 构造函数 */
        public constructor(){
            this.mv = D.App.getMovieClip("bullet", "bullet");
            this.mv.gotoAndPlay("run1", -1);
            this.chairId = 65535;
            this.img = new egret.Bitmap(RES.getRes("im_net_png"));
            this.img.anchorOffsetX = this.img.width / 2;
            this.img.anchorOffsetY = this.img.height / 2;
        }

        /** 设置角度 */
        public setAngle(v:number, s:number, x:number, y:number):void{
            //console.log("setAngle", this.mv.width, this.mv.height, x, y);
            this.mv.anchorOffsetX = this.mv.width / 2;
            this.mv.anchorOffsetY = this.mv.height / 2;
            this.mv.rotation = v;
            this.speed = s;
            this.rad = v * Math.PI / 180;
            this.mv.x = x;
            this.mv.y = y;
        }

        /** 移动 */
        public move(sp:number = 0):void{
            sp = sp || this.speed;
            this.mv.x += Math.sin(this.rad) * sp;
            this.mv.y -= Math.cos(this.rad) * sp;
            if(this.mv.x < 0 || this.mv.x > 1334){
                this.mv.rotation = -this.mv.rotation;
                this.rad = this.mv.rotation * Math.PI / 180;
            }else if(this.mv.y < 0 || this.mv.y > 750){
                this.mv.rotation = -this.mv.rotation + 180;
                this.rad = this.mv.rotation * Math.PI / 180;
            }
            //console.log("move", this.mv.x, this.mv.y);
        }

        /** 删除 */
        public del():void{
            this.mv.parent.addChild(this.img);
            this.img.x = this.mv.x;
            this.img.y = this.mv.y;
            this.img.scaleX = this.img.scaleY = 0;
            this.mv.parent.removeChild(this.mv);
            this.chairId = 65535;
            egret.Tween.get(this.img).to({scaleX:1,scaleY:1}, 300).call(()=>{
                this.img.parent && this.img.parent.removeChild(this.img);
            }, this);
        }

        /** 是否删除 */
        public isClose():boolean{
            return this.chairId == 65535;
        }
    }
}